package com.diankangwo.controller;


import com.diankangwo.constant.resultMsg;
import com.diankangwo.dao.SpeciesDAO;
import com.diankangwo.domain.Species;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 三级分类控制器
 */
@Controller
@Api(description = "三级分类")
public class SpeciesController {

    @Autowired
    private SpeciesDAO speciesDao;

    /**
     * 获取指定二级分类下的三级分类列表
     *
     * @param classID 一级分类ID
     * @return
     */
    @ApiOperation(value = "获取指定二级分类下的三级分类列表", notes = "")
    @ApiImplicitParam(name = "classID", value = "浏览记录ID", required = true, dataType = "Integer")
    @ResponseBody
    @RequestMapping(value = "/species/list", method = RequestMethod.GET)
    public String show(Integer classID) {
        List<Species> speList = speciesDao.findByTypeId(classID);
        String code = "1";
        String msg = "处理异常！";
        if (speList != null) {
            msg = "查询成功！";
        } else {
            msg = "未查询到分类信息！";
        }
        return resultMsg.mapToJson(code, msg, speList);
    }
}
